package com.cea.papyrus.core.presentation.providers;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
import org.eclipse.uml2.uml.edit.providers.PropertyItemProvider;
import org.eclipse.uml2.uml.util.UMLUtil;

/**
 * Extended Property Item provider for properties
 */
public class ExtendedPropertyItemProvider extends PropertyItemProvider {

	/**
	 * @param adapterFactory
	 */
	public ExtendedPropertyItemProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.uml2.uml.edit.providers.PropertyItemProvider#getText(java.lang.Object)
	 */
	@Override
	public String getText(Object object) {
		StringBuffer text = appendType(appendKeywords(new StringBuffer(),
			object), "_UI_Property_type"); //$NON-NLS-1$

		Property property = (Property) object;
		Type type = property.getType();

		if (property.isDerived()) {
			appendString(text, "/"); //$NON-NLS-1$
		}

		String label = property.getLabel(shouldTranslate());

		if (!UML2Util.isEmpty(label)) {
			appendString(text, label);
		} else if (property.getAssociation() != null && type != null) {
			String typeName = type.getName();

			if (!UML2Util.isEmpty(typeName)) {
				appendString(text, Character.toLowerCase(typeName.charAt(0))
					+ typeName.substring(1));
			}
		}

		if (type != null) {
			String typeLabel = type.getLabel(shouldTranslate());

			if (!UMLUtil.isEmpty(typeLabel)) {
				appendString(text, ": " + typeLabel); //$NON-NLS-1$
			} else {
				appendString(text, ": <Unnamed>");
			}
		} else {
			appendString(text, ": <Undefined>");
		}
		
		
		return ExtendedMultiplicityElementItemProvider.appendMultiplicity(text, object).toString();
	}
}
